package rpg.engine.model;

import rpg.util.Objects;
import rpg.util.Strings;

public final class When {
	public static class Builder {
		private String storyID = "";

		private String targetID = "";

		private Type type = null;

		public Builder() {
			super();
		}

		public When build() {
			return new When(this);
		}

		public Builder storyID(final String s) {
			storyID = s;
			return this;
		}

		public Builder targetID(final String s) {
			targetID = s;
			return this;
		}

		public Builder type(final Type t) {
			type = t;
			return this;
		}
	}

	public enum Type {
		ACT_IS, ALWAYS, INVENTORY_HAS, IS_WEARING, TOKEN_MISSING;
	}

	public static final When ALWAYS = new When.Builder().storyID("?")
			.type(Type.ALWAYS).build();

	private final String storyID;

	private final String targetID;
	private final Type type;

	private When(final Builder b) {
		super();
		type = Objects.requireNonNull(b.type, "When.type");
		storyID = Strings.requireNonEmpty(b.storyID, "When.storyID");
		targetID = Strings.trim(b.targetID);
	}

	public String getStoryID() {
		return storyID;
	}

	public String getTargetID() {
		return targetID;
	}

	public Type getType() {
		return type;
	}

	@Override
	public String toString() {
		return "When " + getType() + " for " + getTargetID();
	}
}
